<?php
namespace app\index\controller;
use \think\Controller;
use \think\captcha\Captcha;
use \think\Loader;
use app\index\model\User;

class Reg extends Common
{
    public function index()
    {
        $this->assign('title',"注册");
        return $this->fetch();
    }

    public function add()
    {
    	$postData = input('post.');

    	$validate = Loader::validate('User');

		if(!$validate->check($postData)){
		    $this->error($validate->getError());
		}

    	$postData['password'] = md5($postData['password']);
    	$postData['create_time'] = time();

    	$res = User::create($postData);

    	if($res){
    		$this->success('注册成功');
    	}else{
    		$this->error('注册失败');
    	}
    }

    public function code()
    {
    	$config =    [
		    // 验证码字体大小
		    'fontSize'    =>    30,    
		    // 验证码位数
		    'length'      =>    3,   
		    // 关闭验证码杂点
		    'useNoise'    =>    false, 
		];
		$captcha = new Captcha($config);
		return $captcha->entry();
    }
}

